// 门禁分区
import localforage from "localforage"
localforage.config({
  // driver: [localforage.INDEXEDDB],
  name: 'INDEXDB',
  version: "1.0"
})
let type = "AccessControl"

async function createData() {
  let ac = await localforage.getItem(type) || new Map()
  if (ac.size) return
  let workers = await localforage.getItem("worker") || new Map()
  return localforage.setItem("AccessControl", workers)
}
createData()
export default {
  async query({ name }) {
    let workers = await localforage.getItem(type) || new Map()
    let data = [...workers.values()].filter(item => item.name.includes(name))
    return data
  },

  async delete(keys) {
    let workers = await localforage.getItem(type) || new Map()
    let a = keys.forEach(item => workers.delete(item))
    return localforage.setItem(type, workers)
  },
}